﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "../global/head.h"
#include "../xos/head.h"
#include "../os/vld.h"
#include "export.h"

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 

namespace xos
{
    int create( i_xos ** ppv )
    {
        xos_impl::T * p = 0;
        int ret = 0;

        if( 0 == ret )
        {
            if( ppv )
            {
                *ppv = 0;
            }
            else
            {
                ret = 1; 
            }
        }

        if( ( 0 == ret ) && g_pXos )
        {
            ret = 2;
        }

        if( 0 == ret )
        {
            p = new xos_impl::T;
            if( !p )
            {
                ret = 3;
            }
        }

		if( 0 == ret )
		{
			int r = p->init();
			if( 0 != r )
			{
				ret = 4;
			}
		}

        if( 0 == ret )
        {
            g_pXos = p;
            *ppv = p;
        }
		else if( p )
		{
			p->release();
			p = 0;
		}

        return ret;
    }
}
